package com.pml.bean;

import java.util.HashMap;
import java.util.Map;

public class Register{
    private String name;
    private String age;
    private String email;

    private Map<String,String> map;
    public Register() {
        this.name="";
        this.age="";
        this.email="";
        map=new HashMap<>();
    }

    public boolean isValidate(){
        boolean flag=true;
        if (!this.name.matches("\\w{5,16}")){
            name="";
            map.put("errName","用户名是5-16位的字母或数字");
            flag=false;
        }
        if (!this.age.matches("\\d+")){
            age="";
            map.put("errAge","年龄只能是数字") ;
            flag=false;
        }
        if (!this.email.matches("\\w+@\\w+\\.\\w+")){
            email="";
            map.put("errEmail","email格式错误");
            flag=false;
        }
        return flag;
    }

    public String getErrMsg(String key){
        return map.get(key)==null?"":map.get(key);
    }



    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age =  age;
    }

    public void setEmail(String email){this.email=email;}

    public String getEmail() {
        return email;
    }
}
